<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>学生认证</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2>学生认证</h2>
    </header>
</div>
<div class="header-h" style="padding-top: 1.5rem;"></div>
<section class="html_section bg-f5">
    <div class=" pr30 pl30 bg-fff">
        <ul class="setting_option f26 mt30">
            <!--<li class="between line_center">-->
                <!--<div class="main-s c-999">昵称（不可修改）</div>-->
                <!--<input readonly="" id="name" type="" class="t-r" placeholder="请输入您的昵称" name="">-->
            <!--</li>-->
            <li id="goCity" tapmode class="between line_center">
                <div class="main-s c-999">城市</div>
                <div id="city" class="line_center"><span>选择城市</span></div>
            </li>
            <li id="goSchool" tapmode class="between line_center">
                <div class="main-s c-999">学校</div>
                <div id="school" class="line_center"><span>请选择学校</span></div>
            </li>
            <li id="goClass" tapmode class="between line_center">
                <div class="main-s c-999">在读阶段</div>
                <div id="class" class="line_center"><span>请选择年级</span></div>
            </li>
            <li id="goYear" tapmode class="between line_center">
                <div class="main-s c-999">入学年份</div>
                <div id="year" class="line_center"><span>请选择入学年份</span></div>
            </li>
            <li id="goType" tapmode class="between line_center">
                <div class="main-s c-999">学科</div>
                <div id="schoolType" class="line_center"><span>请选择学科</span></div>
            </li>
            <!--<li tapmode class="between line_center">
                <div class="main-s c-999">学号</div>
                <input readonly="readonly" id="schoolNum" type="" class="t-r" placeholder="请输入学号" name="">
            </li>-->
        </ul>
    </div>
    <div class=" pr30 pl30 pt30 pb40 bg-fff mt20">
        <div class="f30 b">上传资料</div>
        <p class="f22 c-999 mt30">Uni温馨提示：为保证情报局的纯粹性，请所有小伙伴完成本次认证，上传的资料可以是：学生证、校园卡、录取通知书、高考准考证、毕业证书（毕业一年内）</p>
        <div class="activity-detail mt30">
            <ul id="icon_list">

                <li class="choose-pic" id="choosePic" style="display: none;">
                    <div class="pic-icon">拍照/照片</div>
                </li>

            </ul>
            <div class="btn1 mt60" style="display: none;">申请认证</div>
        </div>
    </div>
</section>
</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
    var type = 0;//1是提学号 2是全部重新提交
    var city = '';//城市id
    var school = '';//学校id
    var grade = '';//在读阶段id
    var years = '';//入学年份
    var years_id = '';//入学年份id
    var subject = '';//学科id
    var icon = 0;
    var sex='';
    var tx=0;
    var name ='';
    apiready = function () {
        setFixStatusBar(); //设置状态栏
        keybackListener()
        getMemberInfo();
        listenr();
    }


    //获取用户信息
    function getMemberInfo(reload) {
        var param = {
            token: $api.getStorage('token')
        }
        pop.loading();
        getAjax(Interface.memberIndex, param, function (res) {
            //status状态：1正常 0禁用 2未填写个人信息 3过期全部重新选择 ,默认为2
            //attestation_status 认证状态：1未审核 2审核通过 3审核未通过
            console.log(jsonChange(res))
            var data = res.data;
            $("#name").val(data.name);
            name = data.name;
            if(isDefine(data.city_name)){
                $("#city").html(data.city_name);
                city = data.city;

            }
            if(isDefine(data.school_name)){
                $("#school").html(data.school_name);
                school = data.school;

            }
            if(isDefine(data.entrance_year_id)){
                $("#year").html(data.entrance_year + '年');
                years = data.entrance_year;
                years_id = data.entrance_year_id;
            }
            if(isDefine(data.grade_name)){
                $("#class").html(data.grade_name);
                grade = data.grade_id;

            }
            if(isDefine(data.subject_name)){
                $("#schoolType").html(data.subject_name);
                subject = data.subject_id;

            }
            sex = data.sex;
            tx = data.icon;

            if(isDefine(data.number)){
                $("#schoolNum").val(data.number);
            }else {
                $("#schoolNum").attr('placeholder','未填写学号');
            }

            if (data.attestation_path && data.status == 1) {
                icon = data.attestation_ids;
                console.log(getImg(data.attestation_path[0]));
                $("#icon_list").prepend('<li id="img_li"><img src="' + getImg(data.attestation_path[0]) + '" alt=""></li>');
            }
            //跳过认证时

            // if (data.status == 2 ) {
            //     type = 1;
            //     $("#schoolNum").removeAttr("readonly");
            //     $("#choosePic").show();
            //     $(".btn1").attr("style", "");
            // }else if (data.status == 1 &&  data.attestation_status == 1 && isDefine(data.attestation_path)) {//提交审核，审核正在认证中，再次认证
            //     type = 1;
            //     $("#schoolNum").removeAttr("readonly");
            //     $(".btn1").attr("style", "");
            //     $(".btn1").html("重新认证");
            // } else if (data.status == 1 &&  data.attestation_status == 1) {//提交审核，认证跳过，申请认证
            //     type = 1;
            //     $("#schoolNum").removeAttr("readonly");
            //     $(".btn1").attr("style", "");
            //     $("#choosePic").show();
            // } else if (data.status == 1 && data.attestation_status == 3 ) {//提交审核，审核未通过的,审核被拒绝
            //     type = 1;
            //     $("#schoolNum").removeAttr("readonly");
            //     $(".btn1").attr("style", "");
            //     $("#choosePic").show();
            //     $(".btn1").html("重新认证");
            // } else if (data.status == 3) {//过期的
            //     type = 2;
            //     $("#schoolNum").removeAttr("readonly");
            //     $(".btn1").attr("style", "");
            //     $("#choosePic").show();
            //     $(".btn1").html("重新认证");
            // }
            type = 2;
            /*if(data.attestation_status != 1){
                type = 1;
            }else {
                type = 2;
            }*/
            $("#schoolNum").removeAttr("readonly");
            $(".btn1").attr("style", "");
            $("#choosePic").show();

            if(data.status == 3 || (data.status == 1 && data.attestation_status == 3 ) || (data.status == 1 &&  data.attestation_status == 1 && isDefine(data.attestation_path))){
                $(".btn1").html("重新认证");
            }

            pop.close();
        }, function (error) {
            pop.close();
            pop.notice('读取数据失败');
        })
    }

    $(".btn1").click(function () {
        var param = {};
        if (type == 1) {

            param = {
                token: $api.getStorage('token'),
                type: 2,
                attestation_ids: icon,
                // number: $("#schoolNum").val()
            }
            /*if (!isDefine(param.number)) {
                pop.notice('请填写学号', 2);
                return;
            }*/
            if (!isDefine(param.attestation_ids)) {
                pop.notice('请上传认证资料', 2);
                return;
            }
        }
        if (type == 2) {

            param = {
                token: $api.getStorage('token'),
                type: 1,
                attestation_ids: icon,
                number: $("#schoolNum").val(),
                city: city,
                school: school,
                grade_id: grade,
                subject_id: subject,
                entrance_year: years_id,
                name: name,
                sex:sex,
                icon: tx,
            }

            console.log(jsonChange(param));
            if (!isDefine(param.city) || !isDefine(param.school) || !isDefine(param.grade_id) || !isDefine(param.subject_id) || !isDefine(param.entrance_year)) {
                pop.notice('请完善个人信息', 2);
                return;
            }
            // if (!isDefine(param.number)) {
            //     pop.notice('请填写学号', 2);
            //     return;
            // }
            if (!isDefine(param.attestation_ids)) {
                pop.notice('请上传认证资料', 2);
                return;
            }
        }
        getAjax(Interface.set_member, param, function (res) {
            console.log(JSON.stringify(res))
            pop.notice(res.msg, 1.1, function () {
                comeBack();
            })
            pop.close();

        }, function (error) {
            pop.notice(error.msg)
            pop.close();
        })
    })

    $("#goCity").click(function () {
        /*if (type == 2) {
            commonUrl('../login/select_city', {path: 'schoolRz'})
        }*/
        commonUrl('../login/select_city', {path: 'schoolRz'})
    })
    $("#goSchool").click(function () {
        /*if (type == 2) {
            chooseSchool('../login/select_school');
        }*/
        chooseSchool('../login/select_school');
    })
    $("#goClass").click(function () {
        /*if (type == 2) {
            commonUrl('../login/select_grade', {type: 1});
        }*/
        commonUrl('../login/select_grade', {type: 1});
    })
    $("#goYear").click(function () {
       /* if (type == 2) {
            commonUrl('../login/select_years', {type: 5});
        }*/
        commonUrl('../login/select_years', {type: 5});
    })
    $("#goType").click(function () {
        /*if (type == 2) {
            commonUrl('../login/select_subject', {type: 3});
        }*/
        commonUrl('../login/select_subject', {type: 3});
    })


    $("#choosePic").click(function () {
        uploadbg();
    })

    //上传背景图片
    function uploadbg() {
        uploadHeadPic(function (res) {
            console.log(jsonChange(res));
            if (icon == 0) {
                $("#icon_list").prepend(' <li id="img_li" data-id="' + res.icon + '"><img src="' + getImg(res.path) + '" alt=""></div></li>');
                $(".pic-icon").html('重新上传');
            } else {
                $("#img_li img").attr("src", getImg(res.path));
            }
            icon = res.icon;

        })
    }


    //监听参数
    function listenr() {
        //监听城市
        api.addEventListener({
            name: 'city'
        }, function (ret, err) {
            city = ret.value.id;
            $('#city').html(ret.value.name)
        });
        //监听学校
        api.addEventListener({
            name: 'school'
        }, function (ret, err) {
            school = ret.value.id;
            $('#school').html(ret.value.name)
        });
        //监听年级
        api.addEventListener({
            name: 'grade'
        }, function (ret, err) {
            grade = ret.value.id;
            $('#class').html(ret.value.name)
        });
        //监听入学年份
        api.addEventListener({
            name: 'years'
        }, function (ret, err) {
            years_id = ret.value.id;
            $('#year').html(ret.value.name + '年')
        });
        //监听学科
        api.addEventListener({
            name: 'subject'
        }, function (ret, err) {
            subject = ret.value.id;
            $('#schoolType').html(ret.value.name)
        });
    }

    //选择学校跳转
    function chooseSchool(path) {
        if (!isDefine(city)) {
            pop.notice('请选择城市', 2);
            return;
        } else {
            var param = {
                type: 4,
                city_id: city
            };
            var pathArr = path.split('/');
            var pathName = pathArr[pathArr.length - 1];
            console.log('当前链接路径：' + jsonChange(path));
            api.openWin({
                name: pathName,
                url: path + '.html',
                reload: true,
                pageParam: param
            });
        }
    }


</script>
